'use strict';

function _(txt) {
    return txt;
}
var app = angular.module('app', [])
    .constant('DASHBOARD','/' + Otk.DASHBOARD);
app.controller('loginCtrl', ['$scope', '$http', 'DASHBOARD', function ($scope, $http, DASHBOARD) {
    $scope.error = {};
    $scope.result = {};
    $scope.form = {remember: true};
    $scope.loginLoading = false;
    $scope.submit = function (url) {
        $scope.loginLoading = true;
        $http.post(url, $scope.form).
            success(function (rs, status, headers, config) {
                $scope.loginLoading = false;
                console.log('rs', rs);
                if (rs.result) {
                    window.location.href = '/';
                } else {
                    $scope.error = rs.data;
                    if (rs.message) {
                        $scope.result.message = rs.message;
                    }
                }
            })
            .error(function (res, status, headers, config) {
                console.log('status', status);
                console.log('res', res);
                $scope.loginLoading = false;
                if (status == 422) {
                    $scope.error = res.data;
                    return;
                }
                $scope.result.message = lang.unknown;
            });
    }
}]);